import Vue from 'vue'
import VueRouter from 'vue-router'
import {authGuard} from './guards/index'
import {routerNew} from './routers'

Vue.use(VueRouter)

const router = new VueRouter({
    mode: 'history',
    routes: routerNew
})

// 捕获路由重复跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => {
        if (err.name !== "NavigationDuplicated") {
            throw err
        }
    })
}

// 前置路由守卫
router.beforeEach(authGuard)

export default router
